package com.ghxxzx.daglcustom.business_delegate.service;

import com.ghxxzx.daglcustom.business_delegate.domain.dto.DelegateQuery;
import org.springframework.stereotype.Service;
import org.tmsps.ne4spring.base.BaseService;
import org.tmsps.ne4spring.base.ne.NePage;
import org.tmsps.ne4spring.orm.param.NeParamList;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class DelegateService extends BaseService{

	public NePage list(DelegateQuery delegateQuery) throws ParseException {
		String sql = "select * from d_delegate where status = 0 and (business like ?) and (user = ?)";
		NeParamList params = NeParamList.makeParams();
		params.addLike(delegateQuery.getBusiness());
		params.add(delegateQuery.getUser());
		SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
		if(!delegateQuery.getStart().equals("")) {
			Date startDate = format1.parse(delegateQuery.getStart());
			sql += "and start >= "+startDate.getTime();
		}
		if(!delegateQuery.getEnd().equals("")) {
			Date endDate = format1.parse(delegateQuery.getEnd());
			sql += " and end <= "+endDate.getTime();
		}
		NePage page2 = bs.queryForNePage(sql, params, delegateQuery.getSort(), delegateQuery.getPage());
		return page2;
	}
	
}
